<?php

namespace App\Admin\Controllers\Coll;

use App\Admin\Repositories\Coll\Collection;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class CollectionController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Collection(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('title');
            $grid->column('image')->image('',60,60);
            $grid->column('block');
            $grid->column('debris_num');
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Collection(), function (Show $show) {
            $show->field('id');
            $show->field('title');
            $show->field('image');
            $show->field('block');
            $show->field('debris_num');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $builder = \App\Models\Coll\Collection::with('debris');
        return Form::make($builder, function (Form $form) {
            $form->display('id');
            $form->text('title');
            $form->image('image');
            $form->text('block');
            $form->text('debris_num');
            $form->hasMany('debris', function (Form\NestedForm $form) {
                $form->image('image');
                $form->text('block','地址');
                $form->text('serial','序号');
            })->label('碎片列表');
        });
    }
}
